const base_url = 'http://localhost:8081/wego/api/'

//设置首页页码
const PAGE_NUM = 1
//设置一页显示的条数
const PAGE_SIZE = 10

const IMG_SERVER = 'http://localhost:8082/'
//获取地址栏参数，name:参数名称
function getUrlParms (name) {
  let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
  let r = window.location.search.substr(1).match(reg)
  if (r != null)
    return unescape(r[2])
  return null
}

//显示商品类别
function getCategoryList(){
  $.get(base_url + 'category/v1/indexCategories', function (res) {
    if (res.code == 200) {
      let list = res.data
      let tmp = ''
      for (let i = 0; i < list.length; i++) {
        tmp += '<li><a href="product.html?pid=' + list[i].id + '">' + list[i].name + '</a>'

        tmp += '<div class="chilInPorNav">'

        for (let j = 0; j < list[i].children.length; j++) {
          tmp += '<a href="product.html?id=' + list[i].children[j].id + '">' + list[i].children[j].name + '</a>'
        }

        tmp += '</div>'
        tmp += '</li>'
      }
      $('#categoryUL').empty().html(tmp)

      $('.InPorNav li').hover(function () {
        $(this).addClass('inProNavStyle')
        $(this).children('.chilInPorNav').stop(true, true).show()
      }, function () {
        $(this).removeClass('inProNavStyle')
        $(this).children('.chilInPorNav').stop(true, true).hide()
      })
    }
  })
}

//热门搜索
function getSkuByHot(){
  $.get(base_url + 'spu/getSpuByHot', function (res) {
    // console.info(res)
    if (res.code == 200) {
      let tmp = '热门搜索：'
      for (let i = 0; i < res.data.length; i++) {
        tmp += '<a href="product.html?spuId='+res.data[i].id+'">'+res.data[i].name+'</a>&nbsp;&nbsp;'
      }
      $('#hotDiv').empty().append(tmp)
    }
  })
}
